package com.ljy.helloharmony.slice;

import com.ljy.helloharmony.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

public class SecondAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //第二个界面使用代码的方式编写
        //声明布局
        DependentLayout mLayout=new DependentLayout(this);
        //设置布局大小
        mLayout.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);
        mLayout.setHeight(DependentLayout.LayoutConfig.MATCH_PARENT);
        //设置背景为白色
        ShapeElement element=new ShapeElement();
        element.setRgbColor(new RgbColor(255,255,255));
        mLayout.setBackground(element);
        //创建一个文本
        Text text=new Text(this);
        text.setText("hi harmony");
        text.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);
        text.setTextSize(100);
        text.setTextColor(Color.RED);
        //设置文本布局
        DependentLayout.LayoutConfig layoutConfig=new DependentLayout.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT
        );
        layoutConfig.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
        text.setLayoutConfig(layoutConfig);
        mLayout.addComponent(text);
        super.setUIContent(mLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
